package com.soriya.nestlive.im.message;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.soriya.nestlive.im.constant.MessageType;
import com.soriya.nestlive.im.serializer.MessageTypeDeserializer;
import com.soriya.nestlive.im.serializer.MessageTypeSerializer;
import lombok.Data;

@Data
public class IMMessage<T> {

    @JSONField(serializeUsing = MessageTypeSerializer.class, deserializeUsing = MessageTypeDeserializer.class)
    private MessageType type;

    private Integer state;

    private Long from;

    private Long to;

    private T data;

    public static IMMessage<String> systemMessage(String message) {
        IMMessage<String> _message = new IMMessage<>();
        _message.setType(MessageType.SYSTEM_MESSAGE);
        _message.setTo(0L);
        _message.setFrom(0L);
        _message.setState(1);
        _message.setData(message);
        return _message;
    }

    public static String systemMessageToString(String message) {
        return JSONObject.toJSONString(systemMessage(message));
    }

}
